package cn.iocoder.yudao.module.mqtt.dal.mysql.device;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.mqtt.dal.dataobject.device.DeviceDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.mqtt.controller.admin.device.vo.*;
import org.apache.ibatis.annotations.Param;

/**
 * IoT 设备 Mapper
 *
 * @author 管理员
 */
@Mapper
public interface DeviceMapper extends BaseMapperX<DeviceDO> {

    default PageResult<DeviceDO> selectPage(DevicePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<DeviceDO>()
                .eqIfPresent(DeviceDO::getGroupId, reqVO.getGroupId())
                .eqIfPresent(DeviceDO::getMqttConfigId, reqVO.getMqttConfigId())
                .eqIfPresent(DeviceDO::getMqttClientId, reqVO.getMqttClientId())
                .eqIfPresent(DeviceDO::getDeviceKey, reqVO.getDeviceKey())
                .likeIfPresent(DeviceDO::getDeviceName, reqVO.getDeviceName())
                .likeIfPresent(DeviceDO::getNickname, reqVO.getNickname())
                .eqIfPresent(DeviceDO::getDeviceType, reqVO.getDeviceType())
                .eqIfPresent(DeviceDO::getGatewayId, reqVO.getGatewayId())
                .eqIfPresent(DeviceDO::getNetworkType, reqVO.getNetworkType())
                .eqIfPresent(DeviceDO::getSignalStrength, reqVO.getSignalStrength())
                .eqIfPresent(DeviceDO::getIsOnline, reqVO.getIsOnline())
                .eqIfPresent(DeviceDO::getAddress, reqVO.getAddress())
                .eqIfPresent(DeviceDO::getIsUpload, reqVO.getIsUpload())
                .eqIfPresent(DeviceDO::getFirmwareVersion, reqVO.getFirmwareVersion())
                .eqIfPresent(DeviceDO::getFirmwareId, reqVO.getFirmwareId())
                .eqIfPresent(DeviceDO::getPicUrl, reqVO.getPicUrl())
                .eqIfPresent(DeviceDO::getAreaId, reqVO.getAreaId())
                .eqIfPresent(DeviceDO::getLongitude, reqVO.getLongitude())
                .eqIfPresent(DeviceDO::getLatitude, reqVO.getLatitude())
                .eqIfPresent(DeviceDO::getProvince, reqVO.getProvince())
                .eqIfPresent(DeviceDO::getCity, reqVO.getCity())
                .eqIfPresent(DeviceDO::getDistrict, reqVO.getDistrict())
                .betweenIfPresent(DeviceDO::getCreateTime, reqVO.getCreateTime())
                .inIfPresent(DeviceDO::getId, reqVO.getIdList())
                .orderByDesc(DeviceDO::getId));
    }


    default List<DeviceDO> selectList(DeviceDO reqVO) {
        return selectList( new LambdaQueryWrapperX<DeviceDO>()
                .eqIfPresent(DeviceDO::getGroupId, reqVO.getGroupId())
                .eqIfPresent(DeviceDO::getMqttConfigId, reqVO.getMqttConfigId())
                .eqIfPresent(DeviceDO::getMqttClientId, reqVO.getMqttClientId())
                .eqIfPresent(DeviceDO::getDeviceKey, reqVO.getDeviceKey())
                .likeIfPresent(DeviceDO::getDeviceName, reqVO.getDeviceName())
                .likeIfPresent(DeviceDO::getCountryName, reqVO.getCountryName())
                .likeIfPresent(DeviceDO::getNickname, reqVO.getNickname())
                .eqIfPresent(DeviceDO::getDeviceType, reqVO.getDeviceType())
                .eqIfPresent(DeviceDO::getGatewayId, reqVO.getGatewayId())
                .eqIfPresent(DeviceDO::getNetworkType, reqVO.getNetworkType())
                .eqIfPresent(DeviceDO::getSignalStrength, reqVO.getSignalStrength())
                .eqIfPresent(DeviceDO::getIsOnline, reqVO.getIsOnline())
                .eqIfPresent(DeviceDO::getAddress, reqVO.getAddress())
                .eqIfPresent(DeviceDO::getIsUpload, reqVO.getIsUpload())
                .eqIfPresent(DeviceDO::getFirmwareVersion, reqVO.getFirmwareVersion())
                .eqIfPresent(DeviceDO::getFirmwareId, reqVO.getFirmwareId())
                .eqIfPresent(DeviceDO::getPicUrl, reqVO.getPicUrl())
                .eqIfPresent(DeviceDO::getAreaId, reqVO.getAreaId())
                .eqIfPresent(DeviceDO::getLongitude, reqVO.getLongitude())
                .eqIfPresent(DeviceDO::getLatitude, reqVO.getLatitude())
                .eqIfPresent(DeviceDO::getProvince, reqVO.getProvince())
                .eqIfPresent(DeviceDO::getCity, reqVO.getCity())
                .eqIfPresent(DeviceDO::getDistrict, reqVO.getDistrict())
                .orderByDesc(DeviceDO::getId));
    }

    List<Long> selectByDeviceId(@Param("userId") Long userId);


}